package org.xmonkey.controller.extractor;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IResourceVisitor;
import org.eclipse.core.runtime.CoreException;

/**
 * This class is responsible for the prediction (an 
 * approximation) of the number of classes in this project.
 * This information will be used in the progress monitor
 * while analyzing the content of the project.
 * @author Jacopo Malnati
 *
 */
public final class TicksPredictorVisitor implements IResourceVisitor {
	/**
	 * Here, 1 class = 1 file, while we know it's not always the case,
	 * it's a reasonable approximation
	 */
	private int nrFiles = 0;

	/**
	 * For each *.java file, add 1 to the counter
	 */
	public boolean visit(IResource resource) throws CoreException {
		if(resource.getType() == IResource.FILE){
			if(((IFile)resource).getName().endsWith("java")){
				nrFiles++;
			}
			return false;
		}
		return true;
	}
	
	/**
	 * @return the number of java files in this project
	 */
	public int getNrFiles(){
		return nrFiles;
	}

}
